<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>游记明细</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travelContent.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>

    <script>
        $(function () {
            var params = getParams();
            //如果没有id就直接结束方法
            if (!params.id) {
                return;
            }
            //获取游记内容
            $.get("/travels/" + params.id, function (data) {
                //渲染数据
                $(".travels").renderValues(data, {
                    //和谁旅游(人物)回显
                    getPerson: function (item, value) {
                        var html = "";
                        if (value == 1) {
                            html = "一个人的旅游";
                        } else if (value == 2) {
                            html = "和父母";
                        } else if (value == 3) {
                            html = "和朋友";
                        } else if (value == 4) {
                            html = "和同事";
                        } else if (value == 5) {
                            html = "和爱人";
                        } else if (value == 6) {
                            html = "和其他";
                        }
                        $(item).html(html);
                    }
                });
            });
            //获取当前登录的用户信息
            var user = JSON.parse(sessionStorage.getItem("user"));
            //根据用户id和游记id查询是否已收藏
            $.get('/collects/travels', {userId: user.id, travelId: params.id}, function (data) {
                if (data) {
                    //回显已收藏
                    $("#collectBtn").addClass("fa-star");
                    $("#collectBtn").click(function () {
                        $("#userId").val(user.id);
                        $("#travelId").val(params.id);
                        $("#method").val("DELETE");
                        $("#saveAndDelete").ajaxSubmit(function (data) {
                            alert("取消收藏成功");
                            window.location.reload();
                        })
                    });
                } else {
                    //回显未收藏
                    $("#collectBtn").addClass("fa-star-o");
                    $("#collectBtn").click(function () {
                        $("#userId").val(user.id);
                        $("#travelId").val(params.id);
                        $("#method").val("PUT");
                        $("#saveAndDelete").ajaxSubmit(function (data) {
                            alert("收藏成功");
                            window.location.reload();
                        })
                    });
                }
            });
        })
    </script>
</head>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
        </div>
    </div>
</div>

<div class="travels">
    <img class="cover" render-src="coverUrl">
    <div class="container">
        <h6 class="title" render-html="title"></h6>
        <small>
            <span render-html="createTime"></span>
            浏览 <span> 0</span>
            回复 <span> 0</span>
        </small>
        <div class="row">
            <div class="col-2 img">
                <img class="rounded-circle" render-src="author.headImgUrl">
            </div>
            <div class="col-6 mine">
                <small>
                    <span render-html="author.nickName"></span>
                    <button class="btn" id="followBtn">关注</button>
                    <br>
                    <span render-html="author.travelNum"></span>篇游记
                    <span render-html="author.fanNum"></span>粉丝
                </small>
            </div>
            <div class="attention col">
                <span class="addr" render-html="place.name">广州</span>
            </div>
        </div>
    </div>
    <div class="container">
        <fieldset>
            <legend>我的出行信息</legend>
            <div class="d-flex">
                <div class="p-2  flex-fill">
                    <i class="fa fa-calendar"></i> 出发时间 <span render-html="travelTime"></span>
                </div>
                <div class="p-2  flex-fill"><i class="fa fa-money"></i> 人均费用
                    <span render-html="perExpends"></span></div>
            </div>
            <div class="d-flex">
                <div class="p-2  flex-fill">
                    <i class="fa fa-user-circle"></i> 人物
                    <!--render-key是指从指定对象中的哪个属性获取数据-->
                    <!--render-fun在渲染的时候调用的方法名-->
                    <span render-key="person" render-fun="getPerson"></span>
                </div>
                <div class="p-2  flex-fill"><i class="fa fa-clock-o"></i> 出行天数
                    <span render-html="days"></span>
                </div>
            </div>
        </fieldset>

        <div class="content" render-html="travelContent.content">
        </div>
    </div>

    <hr>

    <div class="container d-flex">
        <div class="p-2  flex-fill">
            <i class="fa fa-thumbs-o-up" id="likeBtn"> </i>
        </div>
        <div class="p-2  flex-fill"><i class="fa  fa-commenting-o" id="commentBtn"> </i>
        </div>
        <div class="p-2  flex-fill"><i class="fa" id="collectBtn"> </i>
            <form id="saveAndDelete" action="/collects/travels" method="post">
                <input type="hidden" name="_method" id="method"/>
                <input type="hidden" name="userId" id="userId"/>
                <input type="hidden" name="travelId" id="travelId"/>
            </form>
        </div>
    </div>
</div>


</body>

</html>